/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.paypaymentdetails.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.paypaymentdetails.entity.PaydayPaymentDetails;
import com.thinkgem.jeesite.modules.paypaymentdetails.service.PaydayPaymentDetailsService;

/**
 * 薪资实付明细Controller
 * @author zxl
 * @version 2017-08-12
 */
@Controller
@RequestMapping(value = "${adminPath}/paypaymentdetails/paydayPaymentDetails")
public class PaydayPaymentDetailsController extends BaseController {

	@Autowired
	private PaydayPaymentDetailsService paydayPaymentDetailsService;
	
	@ModelAttribute
	public PaydayPaymentDetails get(@RequestParam(required=false) String id) {
		PaydayPaymentDetails entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = paydayPaymentDetailsService.get(id);
		}
		if (entity == null){
			entity = new PaydayPaymentDetails();
		}
		return entity;
	}
	
	@RequiresPermissions("paypaymentdetails:paydayPaymentDetails:view")
	@RequestMapping(value = {"list", ""})
	public String list(PaydayPaymentDetails paydayPaymentDetails, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<PaydayPaymentDetails> page = paydayPaymentDetailsService.findPage(new Page<PaydayPaymentDetails>(request, response), paydayPaymentDetails); 
		model.addAttribute("page", page);
		return "modules/paypaymentdetails/paydayPaymentDetailsList";
	}

	@RequiresPermissions("paypaymentdetails:paydayPaymentDetails:view")
	@RequestMapping(value = "form")
	public String form(PaydayPaymentDetails paydayPaymentDetails, Model model) {
		model.addAttribute("paydayPaymentDetails", paydayPaymentDetails);
		return "modules/paypaymentdetails/paydayPaymentDetailsForm";
	}

	@RequiresPermissions("paypaymentdetails:paydayPaymentDetails:edit")
	@RequestMapping(value = "save")
	public String save(PaydayPaymentDetails paydayPaymentDetails, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, paydayPaymentDetails)){
			return form(paydayPaymentDetails, model);
		}
		paydayPaymentDetailsService.save(paydayPaymentDetails);
		addMessage(redirectAttributes, "保存薪资实付明细成功");
		return "redirect:"+Global.getAdminPath()+"/paypaymentdetails/paydayPaymentDetails/?repage";
	}
	
	@RequiresPermissions("paypaymentdetails:paydayPaymentDetails:edit")
	@RequestMapping(value = "delete")
	public String delete(PaydayPaymentDetails paydayPaymentDetails, RedirectAttributes redirectAttributes) {
		paydayPaymentDetailsService.delete(paydayPaymentDetails);
		addMessage(redirectAttributes, "删除薪资实付明细成功");
		return "redirect:"+Global.getAdminPath()+"/paypaymentdetails/paydayPaymentDetails/?repage";
	}

}